package controllers

import java.io.File

import javax.inject.Inject
import play.api.mvc.{AbstractController, ControllerComponents}
import tool.{FormTool, Tool}
import implicits.Implicits._
import play.api.libs.json.Json

/**
 * Created by yz on 11/5/2020
 */
class StatisticController @Inject()(cc: ControllerComponents) extends AbstractController(cc) {

  def toIndex = Action { implicit request =>
    Ok(views.html.statistic.index())
  }

  def getLsFsStatData = Action { implicit request =>
    val file = new File(Tool.statDataDir, "ls_fs.csv")
    val maps = file.csvLines.lineMapNoLower
    Ok(Json.toJson(maps))
  }

  def getStatData = Action { implicit request =>
    val data = FormTool.fileNameForm.bindFromRequest().get
    val file = new File(Tool.statDataDir, data.fileName)
    val maps = file.csvLines.lineMapNoLower
    Ok(Json.toJson(maps))
  }


}
